package com.hhh.springai_test.controller;

import com.hhh.springai_test.common.BaseResponse;
import com.hhh.springai_test.common.ResultUtils;
import com.hhh.springai_test.constant.UserConstant;
import com.hhh.springai_test.model.dto.communityTag.AddCommunityTagDTO;
import com.hhh.springai_test.model.dto.communityTag.UpdateCommunityTagDTO;
import com.hhh.springai_test.model.po.CommunityTag;
import com.hhh.springai_test.service.CommunityTagService;
import cn.dev33.satoken.annotation.SaCheckRole;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/communityTag")
public class CommunityTagController {

    @Resource
    private CommunityTagService communityTagService;

    @PostMapping("/add")
    @SaCheckRole(UserConstant.ADMIN_ROLE)
    public BaseResponse<Long> addCommunityTag(@RequestBody AddCommunityTagDTO addCommunityTagDTO) {
        long result = communityTagService.addCommunityTag(addCommunityTagDTO);
        return ResultUtils.success(result);
    }

    @PostMapping("/delete")
    @SaCheckRole(UserConstant.ADMIN_ROLE)
    public BaseResponse<Boolean> deleteCommunityTag(@RequestParam("id") Long id) {
        boolean result = communityTagService.deleteCommunityTag(id);
        return ResultUtils.success(result);
    }

    @PostMapping("/update")
    @SaCheckRole(UserConstant.ADMIN_ROLE)
    public BaseResponse<Boolean> updateCommunityTag(@RequestBody UpdateCommunityTagDTO updateCommunityTagDTO) {
        boolean result = communityTagService.updateCommunityTag(updateCommunityTagDTO);
        return ResultUtils.success(result);
    }

    @GetMapping("/list")
    public BaseResponse<List<CommunityTag>> listCommunityTags() {
        List<CommunityTag> communityTagList = communityTagService.listCommunityTags();
        return ResultUtils.success(communityTagList);
    }
}
